package com.manjusaka.behavior11.RquestChain;

/**
 * Created by manjusaka on 2017/7/6.
 */
public class RquestChainPattern {

    public static void main(String[] args) {
        RurchaseRequest res = new RurchaseRequest();
        res.setMoney(10);
        res.setNum(2);
        res.setReason("搞事情........");

        Manager003 m3 = new Manager003();
        m3.setHandlerName("和尚");
        Manager002 m2 = new Manager002();
        m2.setHandlerName("赵刚");
        Manager001 m1 = new Manager001();
        m1.setHandlerName("李云龙");

        m3.setHandler(m2);
        m2.setHandler(m1);
        m3.handlerThings(res);

    }
}

/**
 * 采购的请求的类
 * 参数：采购的金额 采购的原因 采购单据
 */
class RurchaseRequest {
    private int num;
    private int money;
    private String reason;

    public RurchaseRequest() {
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        this.money = money;
    }

    public String getReason() {
        return reason;
    }

    public void setReason(String reason) {
        this.reason = reason;
    }
}

/**
 * 处理者的抽象类
 */
abstract class AbstractHandler {
    protected AbstractHandler handler;
    protected String handlerName;

    public void setHandlerName(String handlerName) {
        this.handlerName = handlerName;
    }

    public AbstractHandler() {
    }

    public void setHandler(AbstractHandler handler) {
        this.handler = handler;
    }

    public abstract void handlerThings(RurchaseRequest res);
}

class Manager001 extends AbstractHandler {
    public void handlerThings(RurchaseRequest res) {
        System.out.println(handlerName + "处理......");
    }
}

class Manager002 extends AbstractHandler {
    public void handlerThings(RurchaseRequest res) {
        if (res.getMoney() < 20000) {
            System.out.println(handlerName + "处理......");
        } else {
            handler.handlerThings(res);
        }
    }
}

class Manager003 extends AbstractHandler {
    public void handlerThings(RurchaseRequest res) {
        if (res.getMoney() < 10000) {
            System.out.println(handlerName + "处理......");
        } else {
            handler.handlerThings(res);
        }
    }
}


